﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace Emoney.UserTraining.Admin.aspx
{
    /// <summary>
    /// NetworkMeeting 的摘要说明
    /// </summary>
    public class ajaxNetworkMeeting : IHttpHandler
    {
        BLL.Traning_NetworkMeetingBLL bll = new BLL.Traning_NetworkMeetingBLL();
        public void ProcessRequest(HttpContext context)
        {
            string strReturn = "";
            string strAction = Request["action"];
            //通过反射调用函数
            if (!string.IsNullOrEmpty(strAction))
            {
                System.Reflection.MethodInfo minfo = this.GetType().GetMethod(strAction);
                if (minfo != null)
                {
                    object o = minfo.Invoke(this, new object[] { context });
                    if (o != null)
                        strReturn = o.ToString();
                }
            }
            Response.Write(strReturn);
            Response.End();
        }


        /// <summary>
        /// 查询讲师信息
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        public string GetLecturerById(HttpContext context)
        {
            if (!string.IsNullOrEmpty(Request["id"]))
            {
                BLL.Traning_LecturerBLL tlbll = new BLL.Traning_LecturerBLL();
                Model.Traning_Lecturer model = tlbll.GetModel(Convert.ToInt32(Request["id"]));
                return Comm.JsonTools.ToJson(model);
            }
            else
            {
                return "";
            }
        }

        /// <summary>
        /// 推荐和取消推荐
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        public string recommendNetworkMeeting(HttpContext context)
        {
            if (!string.IsNullOrEmpty(Request["id"]))
            {
                string isRecommend = Request["t"];
                int rows = bll.Recommend(Convert.ToInt32(Request["id"]), isRecommend);
                if (rows > 0)
                {
                    if (isRecommend == "1")
                        return "推荐成功！";
                    else
                        return "取消推荐成功！";
                }
                else
                {
                    if (isRecommend == "1")
                        return "推荐失败，请重新推荐！";
                    else
                        return "取消推荐失败，请重新取消推荐！";
                }
            }
            else
            {
                return "记录不存在";
            }
        }

        /// <summary>
        /// 视频推荐和取消推荐
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        public string VideoRecommend(HttpContext context)
        {
            if (!string.IsNullOrEmpty(Request["id"]))
            {
                string isRecommend = Request["t"];
                int rows = bll.VideoRecommend(Convert.ToInt32(Request["id"]), isRecommend);
                if (rows > 0)
                {
                    if (isRecommend == "1")
                        return "推荐成功！";
                    else
                        return "取消推荐成功！";
                }
                else
                {
                    if (isRecommend == "1")
                        return "推荐失败，请重新推荐！";
                    else
                        return "取消推荐失败，请重新取消推荐！";
                }
            }
            else
            {
                return "记录不存在";
            }
        }

        /// <summary>
        /// 结束会议
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        public string CloseNetworkMeeting(HttpContext context)
        {
            if (!string.IsNullOrEmpty(Request["id"]))
            {
                int rows = bll.deleteAllperson(Convert.ToInt32(Request["id"]));
                if (rows > 0)
                {
                    return "结束成功！";
                }
                else
                {
                    return "结束失败，请重新结束！";
                }
            }
            else
            {
                return "记录不存在";
            }
        }

        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        public string DeleteNetworkMeeting(HttpContext context)
        {
            if (!string.IsNullOrEmpty(Request["id"]))
            {
                int rows = bll.deleteNetworkMeeting(Request["id"]);
                if (rows > 0)
                {
                    return "删除成功！";
                }
                else
                {
                    return "删除失败，请重新删除！";
                }
            }
            else
            {
                return "记录不存在";
            }
        }

        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        public string DeleteTraningLecturer(HttpContext context)
        {
            if (!string.IsNullOrEmpty(Request["id"]))
            {
                BLL.Traning_LecturerBLL tbll = new BLL.Traning_LecturerBLL();
                int rows = tbll.Delete(Convert.ToInt32(Request["id"]));
                if (rows > 0)
                {
                    return "删除成功！";
                }
                else
                {
                    return "删除失败，请重新删除！";
                }
            }
            else
            {
                return "记录不存在";
            }
        }
        /// <summary>
        /// 删除会议类型
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        public string DeleteMeetingType(HttpContext context)
        {
            if (!string.IsNullOrEmpty(Request["id"]))
            {
                BLL.Traning_MeetingTypeBLL tbll = new BLL.Traning_MeetingTypeBLL();
                int rows = tbll.Delete(Convert.ToInt32(Request["id"]));
                if (rows > 0)
                {
                    return "删除成功！";
                }
                else
                {
                    return "删除失败，请重新删除！";
                }
            }
            else
            {
                return "记录不存在";
            }
        }

        public HttpRequest Request
        {
            get { return HttpContext.Current.Request; }
        }

        public HttpResponse Response
        {
            get { return HttpContext.Current.Response; }
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}